/**
 * 
 */
package com.ccrc.lang;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author Jalen
 * ******jdk1.8以上
 * 日期工具类
 */
public class DateUtil {
	
	/**
	 * 
	 * @param dateTime 输入日期 如:2016-12-01 00:00:00
	 * @param pattern formater 如: yyyy-MM-dd HH:mm:ss
	 * @return 格式化后的日期
	 */
	public static Date parse(String dateTime, String pattern) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
		LocalDateTime localDateTime = LocalDateTime.parse(dateTime, formatter);
		Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
		return Date.from(instant);
	}
	
	/**
	 * 获取当前日期
	 * @return
	 */
	public static Date now(){
		LocalDateTime localDateTime = LocalDateTime.now();
		Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
		return Date.from(instant);
	}
	
}
